load("//bazel:skia_rules.bzl", "skia_cc_library", "skia_filegroup", "skia_objc_library")

package(
    default_applicable_licenses = ["//:license"],
)

licenses(["notice"])

skia_filegroup(
    name = "common_hdrs",
    srcs = [
        "DisplayParams.h",
        "WindowContext.h",
    ],
)

skia_filegroup(
    name = "common_srcs",
    srcs = [
        "RasterWindowContext.h",  # only used in tools/window/ so not part of public API
        "WindowContext.cpp",
    ],
)

skia_filegroup(
    name = "common_linux_hdrs",
    srcs = [
        "unix/RasterWindowContext_unix.h",
        "unix/XlibWindowInfo.h",
    ],
)

skia_filegroup(
    name = "common_linux_srcs",
    srcs = [
        "unix/RasterWindowContext_unix.cpp",
    ],
)

skia_filegroup(
    name = "common_mac_hdrs",
    srcs = [
        "mac/RasterWindowContext_mac.h",
    ],
)

skia_filegroup(
    name = "common_mac_srcs",
    srcs = [
        "mac/MacWindowInfo.h",
        "mac/RasterWindowContext_mac.mm",
    ],
)

skia_filegroup(
    name = "common_ios_srcs",
    srcs = [
        "ios/RasterWindowContext_ios.mm",
    ],
)

skia_filegroup(
    name = "common_ganesh_gl_srcs",
    srcs = [
        "GLWindowContext.cpp",
        "GLWindowContext.h",
    ],
)

skia_filegroup(
    name = "linux_ganesh_gl_hdrs",
    srcs = [
        "unix/GaneshGLWindowContext_unix.h",
    ],
)

skia_filegroup(
    name = "linux_ganesh_gl_srcs",
    srcs = [
        "unix/GaneshGLWindowContext_unix.cpp",
    ],
)

skia_filegroup(
    name = "mac_ganesh_gl_hdrs",
    srcs = [
        "mac/GaneshGLWindowContext_mac.h",
    ],
)

skia_filegroup(
    name = "mac_ganesh_gl_srcs",
    srcs = [
        "mac/GaneshGLWindowContext_mac.mm",
        "mac/MacWindowGLUtils.h",
    ],
)

skia_filegroup(
    name = "common_metal_hdrs",
    srcs = [
        "MetalWindowContext.h",
    ],
)

skia_filegroup(
    name = "common_metal_srcs",
    srcs = [
        "MetalWindowContext.mm",
    ],
)

skia_filegroup(
    name = "mac_ganesh_metal_hdrs",
    srcs = [
        "mac/GaneshMetalWindowContext_mac.h",
    ],
)

skia_filegroup(
    name = "mac_ganesh_metal_srcs",
    srcs = [
        "mac/GaneshMetalWindowContext_mac.mm",
    ],
)

skia_filegroup(
    name = "common_vulkan_srcs",
    srcs = [
        "VulkanWindowContext.cpp",
        "VulkanWindowContext.h",
    ],
)

skia_filegroup(
    name = "linux_ganesh_vulkan_hdrs",
    srcs = [
        "unix/GaneshVulkanWindowContext_unix.h",
    ],
)

skia_filegroup(
    name = "linux_ganesh_vulkan_srcs",
    srcs = [
        "unix/GaneshVulkanWindowContext_unix.cpp",
    ],
)

skia_cc_library(
    name = "window",
    testonly = True,
    visibility = ["//tools:__subpackages__"],
    deps = select({
        "@platforms//os:linux": [":window_linux"],
        "@platforms//os:macos": [":window_mac"],
        "@platforms//os:ios": [":window_ios"],
    }),
)

skia_cc_library(
    name = "window_linux",
    testonly = True,
    srcs = [
        ":common_ganesh_gl_srcs",
        ":common_linux_srcs",
        ":common_srcs",
        ":common_vulkan_srcs",
        ":linux_ganesh_gl_srcs",
        ":linux_ganesh_vulkan_srcs",
    ],
    hdrs = [
        ":common_hdrs",
        ":common_linux_hdrs",
        ":linux_ganesh_gl_hdrs",
        ":linux_ganesh_vulkan_hdrs",
    ],
    linkopts = [
        "-lX11",
        "-lxcb",  # dep of X11
        "-lXau",  # dep of xcb
        "-lXdmcp",  # dep of xcb
        "-lX11-xcb",  # needed for Vulkan
    ],
    deps = [
        "//:core",
        "//src/gpu/ganesh:ganesh_TEST_UTIL",
        "//src/gpu/ganesh/gl:ganesh_gl_TEST_UTIL",
        "//src/gpu/ganesh/gl/glx:glx_factory_TEST_UTIL",
        "//src/gpu/ganesh/vk:ganesh_vulkan_TEST_UTIL",
        "//tools/gpu/vk:testutils",
    ],
)

skia_objc_library(
    name = "window_mac",
    testonly = True,
    srcs = [
        "common_ganesh_gl_srcs",
        ":common_mac_srcs",
        ":common_metal_srcs",
        ":common_srcs",
        ":mac_ganesh_gl_srcs",
        ":mac_ganesh_metal_srcs",
    ],
    hdrs = [
        ":common_hdrs",
        ":common_mac_hdrs",
        ":common_metal_hdrs",
        ":mac_ganesh_gl_hdrs",
        ":mac_ganesh_metal_hdrs",
    ],
    sdk_frameworks = [
        "QuartzCore",
        "Cocoa",
        "Foundation",
    ],
    deps = [
        "//:core",
        "//src/gpu/ganesh/gl:ganesh_gl_TEST_UTIL",
        "//src/gpu/ganesh/gl/mac:mac_factory_TEST_UTIL",
        "//src/gpu/ganesh/mtl:ganesh_metal_TEST_UTIL",
        "//tools:tool_utils",
    ],
)

skia_objc_library(
    name = "window_ios",
    testonly = True,
    srcs = [
        "common_ganesh_gl_srcs",
        ":common_ios_srcs",
        ":common_srcs",
    ],
    hdrs = [
        "ios/WindowContextFactory_ios.h",
        ":common_hdrs",
        ":common_metal_hdrs",
        "//tools/sk_app:hdrs",
        "//tools/sk_app/ios:hdrs",
    ],
    deps = [
        "//:core",
        "//src/gpu/ganesh/gl:ganesh_gl_TEST_UTIL",
        "//src/gpu/ganesh/gl/iOS:ios_factory",
        "//tools:tool_utils",
        "//tools/skui",
    ],
)

# TODO(kjlubick): fold this into window above for the backends which depend on graphite
skia_cc_library(
    name = "window_graphite",
    testonly = True,
    hdrs = [
        "GraphiteDisplayParams.h",
    ],
    visibility = ["//tools:__subpackages__"],
    deps = [
        ":window",
        "//tools/graphite:graphite_utils",
    ],
)
